home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / ABox 1.9.5 / CPlus Files / ABResource.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  6.1 KB  |  267 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABResource.c
  15.  
  16. NAME
  17.     ABResource.c, part of the ABox project source code,
  18.     responsible for handling the AboutBox resource (element) class stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                ttempel@monmouth.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <ttempel@monmouth.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     9 June 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  38.                             release and the associated Universal Headers from Apple:
  39.                             most methods that returned references now have "Ref" at
  40.                             the end of their methods names to prevent possible collisions
  41.                             with datatypes and classes of the same name (older versions
  42.                             of the compiler didn't have a problem with this).
  43.     25-oct-95    -    ty    -    changes for "const" usage under CW7; simplification of Boolean
  44.                             query methods
  45.  
  46. */
  47.  
  48. /*===========================================================================*/
  49.  
  50. /*======= Segmentation directives ========*/
  51.  
  52. #ifdef USE_MANUAL_SEGMENTATION
  53. #pragma segment ty
  54. #endif
  55.  
  56. /*============ Header files ==============*/
  57.     
  58. #include     "ABResource.h"
  59.  
  60. /*=============== Globals ================*/
  61.  
  62. /*================ CODE ==================*/
  63.  
  64.  
  65. /*=============================== ABResource::ABResource ================================*/
  66. ABResource::ABResource(void)
  67. {
  68.     mResType = kABbadResourceType;
  69.     mResID = 0;
  70.     mResHandle = NULL;
  71. } // end ABResource
  72.  
  73.  
  74.  
  75. /*=============================== ABResource::~ABResource ================================*/
  76. ABResource::~ABResource(void)
  77. {
  78.     this->ReleaseResource();
  79.  
  80. } // end ~ABResource
  81.  
  82.  
  83.  
  84. /*=============================== ABResource::ReleaseResource ================================*/
  85. OSErr
  86. ABResource::ReleaseResource(void)
  87. {
  88.     OSErr error = noErr;
  89.     
  90.     if (this->ResourceHandleRef())
  91.     {
  92.         ::ReleaseResource(this->ResourceHandleRef());
  93.         this->ResourceHandleRef() = NULL;
  94.         error = ::ResError();
  95.     } 
  96.     return error;
  97.     
  98. } // end ReleaseResource
  99.  
  100.  
  101.  
  102. /*=============================== ABResource::CheckFile ================================*/
  103. Boolean    ABResource::CheckFile(FSSpecPtr fssptr)
  104. {
  105.     OSErr        error = noErr;
  106.     Boolean        fileOK = false;
  107.     short        oldRefNum = CurResFile();
  108.     short        resRefNum;
  109.     
  110.     //    begin here...
  111.     //
  112.     if (fssptr) 
  113.     {
  114.         //    the caller specified a file to use
  115.         resRefNum = ::FSpOpenResFile (fssptr, fsRdPerm);
  116.         error = ResError();
  117.         if (error) 
  118.         {
  119.             ::UseResFile (oldRefNum);
  120.             return false;
  121.         } else {
  122.             ::UseResFile (resRefNum);
  123.         } // end if else block
  124.     } // end if block
  125.  
  126.     this->ResourceHandleRef() = ::Get1Resource (this->ResourceTypeRef(), this->ResID());
  127.     error = ::ResError();
  128.     if (this->ResourceHandleRef() && !error)
  129.         fileOK = true;
  130.     else
  131.         fileOK = false;
  132.  
  133.     if (fssptr) 
  134.     {
  135.         ::CloseResFile(resRefNum);
  136.         ::UseResFile (oldRefNum);
  137.     } // end if block
  138.         
  139.  
  140.     return fileOK;
  141. } // end CheckFile
  142.  
  143.  
  144.  
  145.  
  146. /*=============================== ABResource::Stop ================================*/
  147. OSErr    ABResource::Stop(void)
  148. {
  149.     //    begin here...
  150.     //
  151.     //    subclasses can OVERRIDE this method if they wish, but the intent
  152.     //    here is to halt whatever is going on and free things up if at all possible
  153.     //
  154.     return this->ReleaseResource();
  155.     
  156. } // end Stop
  157.  
  158.  
  159.  
  160.  
  161. /*=============================== ABResource::Initialize ================================*/
  162. OSErr    ABResource::InitializeResource(void)
  163. {
  164.     OSErr        error = noErr;
  165.     
  166.     //    begin here...
  167.     //
  168.     //    subclasses can override this method if they wish, but the intent
  169.     //    here is to perform whatever resource loading/initialize might
  170.     //    be required for the object.
  171.     //
  172.     if (!this->HasResourceHandle())
  173.     {
  174.         this->ResourceHandleRef() = ::GetResource (this->ResourceTypeRef(), this->ResID());   /* IM I pg 119 */
  175.         error = ::ResError();
  176.     } else {
  177.         ::LoadResource(this->ResourceHandleRef());
  178.         error = ::ResError();
  179.     } // end if block
  180.     
  181.     if (this->HasResourceHandle())
  182.         ::HNoPurge(this->ResourceHandleRef());
  183.         
  184.     error = ::ResError();
  185.     return error;
  186. } // end InitializeResource
  187.  
  188.  
  189.  
  190.  
  191. /*=============================== ABResource::GetProperty ================================*/
  192. OSErr    ABResource::GetProperty(ABProperty prop, 
  193.                                 void *ptr, 
  194.                                 long *ptrSize)
  195. {
  196.     OSErr    error = noErr;
  197.     long    pSize;
  198.     
  199.     //    begin here...
  200.     
  201.     if (!ptr)
  202.         return kABPropertyNullStorage;
  203.     
  204.     switch (prop)
  205.     {
  206.         case    kABResourceResType:
  207.                     (*(ResType *)ptr) = this->ResourceTypeRef();
  208.                     pSize = kABResourceResTypeSize;
  209.                     break;
  210.         case    kABResourceResID:
  211.                     (*(short *)ptr) = this->ResID();
  212.                     pSize = kABResourceResIDSize;
  213.                     break;
  214.         case    kABResourceHandle:
  215.                     error = this->InitializeResource();
  216.                     (*(Handle *)ptr) = this->ResourceHandleRef();
  217.                     pSize = kABResourceHandleSize;
  218.                     break;
  219.         default:
  220.                     error = kABResourceSuperProperty::GetProperty(prop, ptr, ptrSize);
  221.                     break;
  222.     } // end switch block
  223.     
  224.     if (ptrSize && !error)
  225.         *ptrSize = pSize;
  226.     return error;
  227.     
  228. } // end GetProperty
  229.  
  230.  
  231.  
  232. /*=============================== ABResource::SetProperty ================================*/
  233. OSErr    ABResource::SetProperty(ABProperty prop, 
  234.                                 void *ptr, 
  235.                                 long ptrSize)
  236. {
  237.     OSErr    error = noErr;
  238.     
  239.     //    begin here...
  240.     
  241.     if (!ptr)
  242.         return kABPropertyNullStorage;
  243.     
  244.     switch (prop)
  245.     {
  246.         case    kABResourceResType:
  247.                     this->ResourceTypeRef() = (*(ResType *)ptr);
  248.                     break;
  249.         case    kABResourceResID:
  250.                      this->ResID() = (*(short *)ptr);
  251.                     break;
  252.         case    kABResourceHandle:
  253.                     this->ResourceHandleRef() = (*(Handle *)ptr);
  254.                     break;
  255.         default:
  256.                     error = kABResourceSuperProperty::SetProperty(prop, ptr, ptrSize);
  257.                     break;
  258.     } // end switch block
  259.     
  260.     return error;
  261.     
  262. } // end SetProperty
  263.  
  264.  
  265.  
  266. //    end of file.
  267.